import time

from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy
from selenium.webdriver.common.by import By
import logging
class AppDriver01():
    _driver=None
    @classmethod
    def get_driver(cls,port=4723,desired_caps={}):
        try:
            if not cls._driver:
                cls._driver=webdriver.Remote(f'http://127.0.0.1:{port}/wd/hub', desired_caps)
                return cls._driver
        except Exception as e:
            logging.error(e)
    @classmethod
    def close_driver(cls):
        if cls._driver:
            cls._driver.quit()
            cls._driver=None


if __name__ == '__main__':
    md=AppDriver01()
    md.get_driver(port=4725,desired_caps={
                'platformName': 'Android',
                'deviceName': '127.0.0.1:62001',
                'platformVersion': '7.1.2',
                # apk包名
                'appPackage': 'com.hexin.plat.android.XinanSecurity',
                # apk的launcherActivity
                'appActivity': 'com.hexin.plat.android.AndroidLogoActivity'
                })
#     md.get_driver(desired_caps=
#         {
#             "platformName": "ios",
#             "platformVersion": "11.2.6",
#             "deviceName": "iPhone 8 Plus",
#             "udid": "d5796c5d5cba895f0ba3336326e47b120fe098d3",
#             "bundleId": "com.swsc.tdx.xnzq",
#             "webDriverAgentUrl": "http://127.0.0.1:8100",
#             "noReset": True,
#             "usePrebuiltWDA": False,
#             "useXctestrunFile": False,
#             "skipLogCapture": True,
#             "automationName": "XCUITest"
#         }
# )
# md.close_driver()